<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .charts-container {
            display: grid;
            grid-template-columns: 1fr 1fr 1fr;
            gap: 10px;
            background-color:#fefaff;
        }
        .charts-item {
            background-color:#fff;
        }
    </style>
</head>
<body>
<div class="charts-container">
    <div class="charts-item" id="main" style="width: 600px;height:400px;"></div>
    <div class="charts-item" id="main1" style="width: 600px;height:400px;"></div>
    <div class="charts-item" id="main2" style="width: 600px;height:400px;"></div>
</div>
<!-- 为 EChart 准备一个定义了宽高的 DOM -->
<!--<div id="main" style="width: 600px;height:400px;"></div>-->
<!--<div id="main1" style="width: 600px;height:400px;"></div>i-->

<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script>
<script>

        $(function () {
        $.ajax({
            url: "yg.php",
            success(res) {
                if (res.code == 1) {
                    drawCharts1(res.data.x, res.data.y)
                }
            },
            error() {

            }
        })
    })
        $(function () {
            $.ajax({
                url: "sex.php",
                success(res) {
                    if (res.code == 1) {
                        drawCharts2(res.data.sex)
                    }
                },
                error() {

                }
            })
        })
        $(function () {
            $.ajax({
                url: "gz.php",
                success(res) {
                    if (res.code == 1) {
                        drawCharts3(res.data.x, res.data.y)
                    }
                },
                error() {

                }
            })
        })

</script>
<script type="text/javascript">
    function drawCharts1(xData, yData) {
        // 基于准备好的dom，初始化echarts实例
        var chartDom = document.getElementById('main');
        var myChart = echarts.init(chartDom);


        // 指定图表的配置项和数据
        var option = {
            title: {
                text: '各部门人数统计'
            },
            tooltip: {},
            legend: {
                data: ['人数']
            },
            xAxis: {
                data: xData
            },
            yAxis: {},
            series: [
                {
                    name: '人数',
                    type: 'bar',
                    data: yData
                }
            ]
        };

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    }
    function drawCharts2(sex) {
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('main1'));

        // 指定图表的配置项和数据
        var option = {
            title: {
                text: 'Referer of a Website',
                subtext: 'Fake Data',
                left: 'center'
            },
            tooltip: {
                trigger: 'item'
            },
            legend: {
                orient: 'vertical',
                left: 'left'
            },
            series: [
                {
                    name: 'Access From',
                    type: 'pie',
                    radius: '50%',
                    data: sex,
                    emphasis: {
                        itemStyle: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                }
            ]
        };


        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    }

    function drawCharts3(x,y) {
        var chartDom = document.getElementById('main2');
        var myChart = echarts.init(chartDom);
        var option;

        option = {
            title: {
                text: '张三工资表',
                backgroundColor:'ff0000',

                left: 'center',
                titleStyle: {
                    color: '#333',
                },

            },


            xAxis: {
                type: 'category',
                data: y
            },
            yAxis: {
                type: 'value'
            },
            series: [
                {
                    data: x,
                    type: 'line'
                }
            ]
        };

        option && myChart.setOption(option);
        var img = new Image();
        img.src = myChart.getDataURL({
            pixelRatio: 2,
            backgroundColor: '#fff'
        });
    }


</script>
</body>
</html>